package src;

import java.util.Scanner;

import java.util.Scanner;

public class DingYi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数组的长度");
        int shuzushuliang = sc.nextInt();
        //设计一个方法用于遍历数组  求出最大值并返回  输入一个数字判断是否存在返回
        //遍历数组
        int[] arr = new int[shuzushuliang];

        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第"+(i+1)+"个数");
            int shuzushu = sc.nextInt();
            arr[i] = shuzushu;
        }
        //设计一个数组   ↑
        System.out.println("请输入一个数字，系统会判断这个数是否存在于数组中");
        int shuru = sc.nextInt();


        System.out.println(fangfa3(shuru,arr));
        fangfa1(arr);
        System.out.println();
        System.out.print("您输入的这组数字中最大的为"+"   ");
        System.out.println(fangfa2(arr));

        /*System.out.print("遍历数组的结果为");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
        System.out.println();*/
        //遍历数组   ↑



        /*int linshisuzi = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if(linshisuzi<arr[i]){
                linshisuzi = arr[i];
            }
        }
        System.out.print("您输入的这组数字中最大的为"+"   "+linshisuzi);
        System.out.println();*/
        //求出数组内的最大值


        /*System.out.println("请输入一个数字，系统会判断这个数是否存在于数组中");
        int shuru = sc.nextInt();
        for (int i = 0; i < arr.length; i++) {
            if (shuru == arr[i]){
                System.out.println(true);
            }
            else {
                System.out.println(false);
            }
        }*/
        //判断数字是否在数组中   ↑
    }
    public static void fangfa1(int[] arr) {

        System.out.print("遍历数组的结果为");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
    public static int fangfa2(int[] arr) {
        int linshisuzi = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (linshisuzi < arr[i]) {
                linshisuzi = arr[i];
            }
        }
        //System.out.print("您输入的这组数字中最大的为" + "   " + linshisuzi);
        //System.out.println();
        return linshisuzi;
    }
    public static boolean fangfa3(int shuru,int[]arr) {
        //System.out.println("请输入一个数字，系统会判断这个数是否存在于数组中");
        for (int i = 0; i < arr.length; i++) {
            if (shuru == arr[i]) {
                //System.out.println(true);
                return true;
                //System.out.println(false);
            }

        }
        return false;
    }
}
